package com.softwinner.timerswitch.ui;


import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.PowerManager;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import com.hjq.toast.ToastUtils;
import com.softwinner.timerswitch.R;

public class DialogShutdownTipYhk extends Activity {
    private Context mContext;
    private TextView mTextView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        int flags = WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON | WindowManager.LayoutParams.FLAG_IGNORE_CHEEK_PRESSES | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
        getWindow().addFlags(flags);

        setContentView(R.layout.dialog_shutdown_yhk);
        mContext = this;


        PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
//        pm.wakeUp(SystemClock.uptimeMillis(), 7, "Shutdown countdown");


        mTextView = findViewById(R.id.shutdownTip);
        findViewById(R.id.cancel_yhk).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mCountDownTimer != null) {
                    //android.util.Log.e("yulh","  cancel ");
                    mCountDownTimer.cancel();
                }
                finish();
            }
        });
        //findViewById(R.id.confirm_yhk).setOnClickListener(new View.OnClickListener() {
        //    @Override
        //    public void onClick(View v) {
        //        Intent intent = new Intent(Settings.ACTION_INTERNAL_STORAGE_SETTINGS);
        //		  intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        //        startActivity(intent);			
        //        finish();
        //    }
        //});
        timerTest();
    }


    private CountDownTimer mCountDownTimer;

    private void timerTest() {

        mCountDownTimer = new CountDownTimer(15000, 1000) {

            public void onTick(long millisUntilFinished) {
                //mTextField.setText("seconds remaining: " + millisUntilFinished / 1000);
                //android.util.Log.e("yulh","  s "+(millisUntilFinished/1000));
                if (mTextView != null) {
                    mTextView.setText(" " + (millisUntilFinished / 1000) + " ");
                }
            }

            public void onFinish() {
                if (mContext == null) {
                    return;
                }
                ToastUtils.show("删除代码了");
                //android.util.Log.d("yulh","*** truely shutdown ***");
                /*Intent intent = new Intent(Intent.ACTION_REQUEST_SHUTDOWN);
                intent.putExtra("android.intent.extra.KEY_CONFIRM", false);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                mContext.startActivity(intent);*/
                finish();
            }
        }.start();

    }

}